<%@page contentType="text/html" import ="java.sql.*, javax.naming.*, javax.sql.*" pageEncoding="UTF-8"%><%
//create table elookinto_ll ( ip varchar(40) ,  page varchar(40), create_date datetime, update_date datetime, count integer(18), license_expired_date datetime, license_issue_date datetime, user_id varchar(30), license_key varchar(40), primary key (ip, page, license_key, user_id));
    String ip = request.getRemoteAddr();
    String webPage = request.getParameter("page");
    String user = request.getRemoteUser();
    if (user == null) {
      user = "";
    }
    if (webPage == null) {
      webPage = request.getHeader("referer");
      ;
      if (webPage == null) {
        webPage = "unknown";
      }
    }
    Connection con = null;
    PreparedStatement st = null;
    ResultSet rs = null;
    try {
      Context initContext = new InitialContext();
      Context envContext = (Context) initContext.lookup("java:/comp/env");
      DataSource ds = (DataSource) envContext.lookup("jdbc/log");
      con = ds.getConnection();

     st = con.prepareStatement("INSERT INTO elookinto_ll (ip, page, user_id, license_key, create_date, update_date, license_expired_date, count) VALUES (?,?, ?, '', sysdate(),sysdate(), adddate(sysdate(),365), 1)"
              + " ON DUPLICATE KEY  UPDATE update_date = sysdate(), count=count+1");
      st.setString(1, ip);
      st.setString(2, webPage);
      st.setString(3, user);
      st.execute();
      st.close();
      st = con.prepareStatement("SELECT license_expired_date  - sysdate() FROM elookinto_ll WHERE ip=? and page = ? and user_id=? and license_key=? ");
      st.setString(1, ip);
      st.setString(2, webPage);
      st.setString(3, user);
      st.setString(4, "");
      //Statement st2 = con.createStatement();
      rs = st.executeQuery();
      if (rs.next())
        {
           if (rs.getDouble(1)>0) out.println("true");
           return;
        }


    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      if (rs != null) {
        rs.close();
      }
      if (st != null) {
        st.close();
      }
      if (con != null) {
        con.close();
      }
    }
    out.println("false");
%>